import {defineConfig} from 'vite'
import {resolve} from 'path';
import react from '@vitejs/plugin-react-swc'
import {visualizer} from 'rollup-plugin-visualizer'
import viteCompression from 'vite-plugin-compression';
import {createSvgIconsPlugin} from 'vite-plugin-svg-icons'

const isProd = process.env.NODE_ENV === 'production';
export default defineConfig({
    publicDir: 'public', // 静态资源服务的文件夹
    server: {
        open: true
    },
    build: {
        rollupOptions: {},
        minify: 'esbuild',
        terserOptions: {
            compress: {
                //生产环境时移除console
                drop_console: true,
                drop_debugger: true,
            },
        },
    },
    resolve: {
        alias: {
            '@': resolve(__dirname, './src')
        }
    },
    plugins: [
        react(),
        isProd && visualizer(),
        isProd && viteCompression(),
        createSvgIconsPlugin({
            iconDirs: [resolve(process.cwd(), 'src/assets/svg')],
            symbolId: "icon-[name]"
        })
    ],
})
